<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-project-edit" th:object="${project}">
			<input id="projectId" name="projectId" type="hidden" th:field="*{projectId}"/>
			<div class="form-group">
				<label class="col-sm-3 control-label ">项目名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="projectName" id="projectName" th:field="*{projectName}"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">显示顺序：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="orderNum" id="orderNum" th:field="*{orderNum}">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">状态：</label>
				<div class="col-sm-8">
					<div class="onoffswitch">
                         <input type="checkbox" th:checked="${project.status == '0' ? true : false}" class="onoffswitch-checkbox" id="status" name="status">
                         <label class="onoffswitch-label" for="status">
                             <span class="onoffswitch-inner"></span>
                             <span class="onoffswitch-switch"></span>
                         </label>
                     </div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" class="form-control" type="text" th:field="*{remark}">
				</div>
			</div>
		</form>
	</div>
	<div th:include="include::footer"></div>
	<script th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
	<script type="text/javascript">
		$("#form-project-edit").validate({
			rules:{
				projectName:{
					required:true,
					remote: {
		                url: ctx + "system/project/checkProjectNameUnique",
		                type: "post",
		                dataType: "json",
		                data: {
							"projectId": function() {
							    return $("#projectId").val();
							},
							"projectName": function() {
							    return $.common.trim($("#projectName").val());
							}
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				},
				orderNum:{
					required:true,
					digits:true
				},
			},
			messages: {
		        "projectName": {
		            remote: "项目名称已经存在"
		        }
		    }
		});

		function edit() {
			var projectId = $("input[name='projectId']").val();
			var projectName = $("input[name='projectName']").val();
			var orderNum = $("input[name='orderNum']").val();
			var status = $("input[name='status']").is(':checked') == true ? 0 : 1;
			var remark = $("input[name='remark']").val();
			$.ajax({
				cache : true,
				type : "POST",
				url : ctx + "system/project/edit",
				data : {
					"projectId": projectId,
					"projectName": projectName,
					"orderNum": orderNum,
					"status": status,
					"remark": remark
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.successCallback(data);
				}
			});
		}
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	edit();
	        }
	    }
	</script>
</body>
</html>
